#include <QIcon>
#include <QMouseEvent>
#include "tabbar.h"

TabBar::TabBar(QWidget *parent) :
	QWidget(parent),
	tabBar(new QTabBar(this)),
	layout(new QHBoxLayout(this)),
	buttonAddTab(new QPushButton(this)),
	horizontalSpacer(new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum))
{
	layout->setSpacing(3);
	layout->setObjectName(QString::fromUtf8("layout"));
	layout->setContentsMargins(0, 0, 0, 0);
	tabBar->setObjectName(QString::fromUtf8("tabBar"));
	tabBar->setMaximumSize(QSize(16777215, 25));
	layout->addWidget(tabBar);
	buttonAddTab->setObjectName(QString::fromUtf8("buttonAddTab"));
	buttonAddTab->setMinimumSize(QSize(30, 30));
	buttonAddTab->setMaximumSize(QSize(30, 30));
	QIcon icon;
	QString iconThemeName = QString::fromUtf8("add");
	if (QIcon::hasThemeIcon(iconThemeName))
		icon = QIcon::fromTheme(iconThemeName);
	else
		icon.addFile(QString::fromUtf8(""), QSize(), QIcon::Normal, QIcon::Off);
	buttonAddTab->setIcon(icon);
	buttonAddTab->setFlat(true);
	layout->addWidget(buttonAddTab);
	layout->addItem(horizontalSpacer);
	setLayout(layout);
	QMetaObject::connectSlotsByName(this);
	tabBar->installEventFilter(this);
	connect(tabBar, SIGNAL(currentChanged(int)), this, SLOT(emit_selectedTabChanged(int)));
	connect(buttonAddTab, SIGNAL(clicked()), this, SLOT(emit_tabCreated()));
}
void TabBar::mouseReleaseEvent(QMouseEvent *event) {
	if(event->button() == Qt::MidButton)
		removeTab(tabBar->tabAt(event->pos()));
}


